import logging
import unittest
import requests

from api.approveAPI import approveAPI
from api.loginAPI import loginAPI
from utils import assert_utils


class approve(unittest.TestCase):
    realname = '张三'
    cardId = '110101199003145351'

    def setUp(self) -> None:
        self.login_api = loginAPI()
        self.approve_api = approveAPI()
        self.session = requests.Session()

    def tearDown(self) -> None:
        self.session.close()

    # 认证成功
    def test01_approve_success(self):
        response = self.login_api.login(self.session, keywords="17688880002")
        logging.info('login response = {}'.format(response.json()))
        assert_utils(self, response, 200, 200, '登录成功')
        response = self.approve_api.approve(self.session, self.realname, self.cardId)
        logging.info('approve response = {}'.format(response.json()))
        assert_utils(self, response, 200, 200, '提交成功!')

    # 认证失败_姓名为空
    def test02_realname_null_approve_fail(self):
        response = self.login_api.login(self.session, keywords="17688880001")
        logging.info('login response = {}'.format(response.json()))
        assert_utils(self, response, 200, 200, '登录成功')
        response = self.approve_api.approve(self.session, '', self.cardId, )
        logging.info('approve response = {}'.format(response.json()))
        assert_utils(self, response, 200, 100, '姓名不能为空')

    # 认证失败_身份证号为空
    def test03_cardId_null_approve_fail(self):
        response = self.login_api.login(self.session, keywords="17688880001")
        logging.info('login response = {}'.format(response.json()))
        assert_utils(self, response, 200, 200, '登录成功')
        response = self.approve_api.approve(self.session, self.realname,'' )
        logging.info('approve response = {}'.format(response.json()))
        assert_utils(self, response, 200, 100, '身份证号不能为空')

    # 获取认证信息
    def test03_get_approve(self):
        response = self.login_api.login(self.session, keywords="17688880002")
        logging.info('login response = {}'.format(response.json()))
        assert_utils(self, response, 200, 200, '登录成功')
        response = self.approve_api.getApprove(self.session)
        logging.info('getapprove response = {}'.format(response.json()))
        self.assertEqual(200,response.status_code)